package com.houtai.service.campus;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houtai.bean.dto.article.CampusArticleListDto;
import com.houtai.bean.dto.campus.CampusDetailDto;
import com.houtai.bean.dto.campus.CampusListDto;
import com.houtai.bean.dto.campus.TdCampusMapListDto;
import com.houtai.bean.vo.campus.TdCampusMapListVo;
import com.houtai.bean.vo.article.ArticleList;
import com.houtai.bean.vo.article.CampusArticleListVo;
import com.houtai.bean.vo.brand.TdBrandList;
import com.houtai.bean.vo.brand.TdBrandListResult;
import com.houtai.bean.vo.campus.*;
import com.houtai.dao.TdBrandDao;
import com.houtai.dao.TdCampusDao;
import com.houtai.dao.TsJzArticleInfoDao;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CampusService {
    private static Logger logger = Logger.getLogger(CampusService.class);
    @Autowired
    private TdCampusDao tdCampusDao;
    @Autowired
    private TdBrandDao tdBrandDao;
    @Autowired
    private TsJzArticleInfoDao tsJzArticleInfoDao;
    /**
     * @Purpose:    园区列表
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ArticleListVo
     */
    public TdCampusMapListVo campusList(TdCampusMapListDto dto) {
        String logInfo = this.getClass().getName() + ":campusList:";
        TdCampusMapListVo retInfo = new TdCampusMapListVo();
        logger.info("======" + logInfo + "begin======");
        try {

            List<TdCampusMapList> lists = tdCampusDao.findTdCampusMapList(dto);
            if (lists != null && lists.size() > 0) {
                retInfo.setList(lists);
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无园区信息");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    园区榜单前十
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     TdBrandListResult
     */
    public TdBrandListResult tdBrandList() {
        String logInfo = this.getClass().getName() + ":tdBrandList:";
        TdBrandListResult retInfo = new TdBrandListResult();
        logger.info("======" + logInfo + "begin======");
        try {
            List<TdBrandList> list = tdBrandDao.findTdBrandList();
            if (list != null && list.size() > 0) {
                retInfo.setList(list);
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无品牌榜单信息");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    园区榜单前十
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ArticleListVo
     */
    public CampusTopListVo campusTopList() {
        String logInfo = this.getClass().getName() + ":campusTopList:";
        CampusTopListVo retInfo = new CampusTopListVo();
        logger.info("======" + logInfo + "begin======");
        try {
            List<CampusTopList> list = tdCampusDao.findCampusTopList();
            if (list != null && list.size() > 0) {
                retInfo.setList(list);
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无园区信息");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    园区指数前十
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ArticleListVo
     */
    public CampusTopListVo campusIndexList() {
        String logInfo = this.getClass().getName() + ":campusIndexList:";
        CampusTopListVo retInfo = new CampusTopListVo();
        logger.info("======" + logInfo + "begin======");
        try {
            List<CampusTopList> list = tdCampusDao.findCampusIndexList();
            if (list != null && list.size() > 0) {
                retInfo.setList(list);
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无园区信息");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    园区列表
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ArticleListVo
     */
    public CampusListVo campusList(CampusListDto dto) {
        String logInfo = this.getClass().getName() + ":campusList:";
        CampusListVo retInfo = new CampusListVo();
        logger.info("======" + logInfo + "begin======");
        try {
            String orderBy = "campus_id DESC";

            PageHelper.startPage(dto.getCurrent_page(), dto.getPage_size(), orderBy);
            List<CampusList> lists = tdCampusDao.findCampusList(dto);
            PageInfo<CampusList> list = new PageInfo<>(lists);
            if (list.getTotal() > 0) {
                retInfo.setCurrent_page(dto.getCurrent_page());
                retInfo.setList(list.getList());
                retInfo.setPage_size(list.getPageSize());
                retInfo.setTotal_record(list.getTotal());
                retInfo.setPages(list.getPages());
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无园区信息");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    园区详情
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     CampusDetailVo
     */
    public CampusDetailVo campusDetail(CampusDetailDto dto) {
        String logInfo = this.getClass().getName() + ":campusDetail:";
        CampusDetailVo retInfo = new CampusDetailVo();
        logger.info("======" + logInfo + "begin======");
        try {
            CampusDetail detail = tdCampusDao.findCampusDetail(dto.getCampus_id());
            if (detail != null) {
                retInfo.setDetail(detail);
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("园区详情不存在");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    文章列表
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ArticleListVo
     */
    public CampusArticleListVo articleList(CampusArticleListDto dto) {
        String logInfo = this.getClass().getName() + ":articleList:";
        CampusArticleListVo retInfo = new CampusArticleListVo();
        logger.info("======" + logInfo + "begin======");
        try {

            PageHelper.startPage(dto.getCurrent_page(), dto.getPage_size(), "arti_scort DESC, id DESC");
            List<ArticleList> lists = tsJzArticleInfoDao.findCampusArticleList(dto);
            PageInfo<ArticleList> list = new PageInfo<>(lists);
            if (list.getTotal() > 0) {

                retInfo.setCurrent_page(dto.getCurrent_page());
                retInfo.setList(list.getList());
                retInfo.setPage_size(list.getPageSize());
                retInfo.setTotal_record(list.getTotal());
                retInfo.setPages(list.getPages());
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无文章");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
